<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 -->
        <TableHeader
            :buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
            :quick-search-placeholder="t('Quick search placeholder', { fields: 'ID/标题/简介'})"
        />

        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table ref="tableRef" />

        <!-- 表单 -->
        <PopupForm width="60%"/>
    </div>
</template>

<script setup lang="ts">
import { ref, provide } from 'vue'
import baTableClass from '/@/utils/baTable'
import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
import { defaultOptButtons } from '/@/components/table'
import { baTableApi } from '/@/api/common'
import { useI18n } from 'vue-i18n'

defineOptions({
    name: 'goods/goods',
})

const { t } = useI18n()
const tableRef = ref()
const baTable = new baTableClass(
    new baTableApi('/admin/goods.Goods/'),
    {
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('Id'), prop: 'id', align: 'center', operator: '=', operatorPlaceholder: t('Id'), width: 70 },
            { label: "图片", prop: 'feng', align: 'center', render: 'image', operator: false, width:85 },
            { label: "标题", prop: 'title', align: 'left', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
            { label: "价格", prop: 'price', align: 'center', operator: '=', operatorPlaceholder: t('Fuzzy query'),width:110 },
            { label: "库存", prop: 'stock', align: 'center', operator: false, operatorPlaceholder: t('Fuzzy query'),width:100},
            { label: "销量", prop: 'sell_num', align: 'center', operator: false, operatorPlaceholder: t('Fuzzy query'),width:100},
            { label: "浏览", prop: 'hits', align: 'center', operator: false, operatorPlaceholder: t('Fuzzy query'),width:100},
            { label: "简介", prop: 'des', align: 'left', operator: '=', operatorPlaceholder: t('Fuzzy query'),width:150},

            { label: '分类',prop: 'cat_id', align: 'center',show:false, operator: '=' ,comSearchRender:'remoteSelect',remote: { pk: 'id', field: 'name', remoteUrl: '/admin/goods.GoodsCat/goodscatList' }},
            {
                label: "分类",
                prop: 'cat.name',
                align: 'center',
                operator: false,
                operatorPlaceholder: t('Fuzzy query'),
                render: 'tag',
                width:150
            },
    
            { label:"置顶", prop: 'is_top', align: 'center', operator:false,render: 'tag', sortable: false,replaceValue: { '0':'否', '1':'是', 'null':'否'},custom:{0:'danger',1:'success',null:'danger'},width:100},
            { label: "发布时间", prop: 'create_time', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 170 },
            { label: "展示", prop: 'status', align: 'center', width: '80', render: 'switch'},
            {
                label: t('Operate'),
                align: 'center',
                width: '120',
                render: 'buttons',
                buttons: defaultOptButtons(['edit', 'delete']),
                operator: false,
            },
        ],
        dblClickNotEditColumn: [undefined],
    },
    {
        defaultItems: {
            pro_type: 0,
            money: '0',
            status: true,
            specs:0,
            is_top:false
        },
    }
)

baTable.mount()
baTable.getIndex()

provide('baTable', baTable)
</script>

<style scoped lang="scss"></style>
